package com.wmcsk;

import android.content.Context;
import android.os.Bundle;

import com.wmcsk.dl.util.LogUtils;
import com.wmcsk.interfaces.InitResultListener;
import com.wmcsk.interfaces.KuaiyanSignSdkInterface;
import com.wmcsk.interfaces.SignActivityStartListener;


/**
 * Created by wm on 2017/12/20.
 */
public class KuaiyanSignSdk implements KuaiyanSignSdkInterface {
    private static KuaiyanSignSdk kuaiyanSdk;
    public static final String ERROR_TAG = "KuaiyanSignSdk";
    private KuaiyanSignSdk(){

    }
    private KuaiyanSignSdkInterface kuaiyanSignSdkInterface;
    public void initKYSdkInterface(KuaiyanSignSdkInterface kuaiyanSignSdkInterface){
        this.kuaiyanSignSdkInterface = kuaiyanSignSdkInterface;
    }
    public static KuaiyanSignSdk getInstance(){
        if(kuaiyanSdk == null){
            synchronized (KuaiyanSdk.class){
                if(kuaiyanSdk == null){
                    kuaiyanSdk = new KuaiyanSignSdk();
                }
            }
        }
        return kuaiyanSdk;
    }
    @Override
    public String getVersion() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return "null";
        }
        return kuaiyanSignSdkInterface.getVersion();
    }

    @Override
    public void init(Context context, InitResultListener initResultListener) {
        if(kuaiyanSignSdkInterface == null) {
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            if(initResultListener!=null){
                initResultListener.initResult(-10);
            }
            return;
        }
        kuaiyanSignSdkInterface.init(context,initResultListener);
    }

    @Override
    public String getSdkInfo() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return "null";
        }
        return kuaiyanSignSdkInterface.getSdkInfo();
    }

    @Override
    public void startSignActivity(Bundle bundle, SignActivityStartListener signActivityStartListener) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            if(signActivityStartListener!=null){
                signActivityStartListener.lunchSignActivityError(-10,"初始化未完成",new RuntimeException("初始化未完成"));
            }
            return;
        }
        kuaiyanSignSdkInterface.startSignActivity(bundle,signActivityStartListener);
    }
}
